package com.wei.frame;

import android.app.Application;
import android.content.Context;

import com.wei.frame.di.component.AppComponent;
import com.wei.frame.di.component.DaggerAppComponent;
import com.wei.frame.ui.imageloader.ImageLoader;

import javax.inject.Inject;

import dagger.Lazy;

/**
 * 作者：赵若位
 * 时间：2020/8/20 2:16
 * 邮箱：1070138445@qq.com
 * 功能：
 */
public class App extends Application
{
    private static AppComponent sComponent;

    @Inject
    Context sContext;
    @Inject
    Lazy<ImageLoader> mImageLoaderLazy;

    @Override
    public void onCreate()
    {
        super.onCreate();
        sComponent = DaggerAppComponent.builder()
                .application(this)
                .build();
        sComponent.inject(this);
    }

    public static AppComponent getComponent()
    {
        return sComponent;
    }

    @Override
    public void onTrimMemory(int level)
    {
        super.onTrimMemory(level);
        if (null != mImageLoaderLazy.get())
        {
            mImageLoaderLazy.get().onTrimMemory(this,level);
        }
    }

    @Override
    public void onLowMemory()
    {
        super.onLowMemory();
        if (null != mImageLoaderLazy.get())
        {
            mImageLoaderLazy.get().onLowMemory(this);
        }
    }
}
